<template>
	<view class="my_kefang">
		
		
		<view class="table_box" style="margin: 20px 0;">
			<uni-table border stripe emptyText="暂无更多数据">
				<!-- 表头行 -->
				<uni-tr>
					<uni-th width="40" align="center">用户</uni-th>
					<uni-th width="40" align="center">账号</uni-th>
					<uni-th width="80" align="left">服务类目</uni-th>
					<uni-th width="80" align="left">状态</uni-th>
					<uni-th width="80" align="left">操作</uni-th>
				</uni-tr>
				<!-- 表格数据行 -->
				<uni-tr v-for="(item, index) in list" :key="index">
					<uni-td>{{item.user_name}}</uni-td>
					<uni-td >
					{{item.user_accout}}
					
					</uni-td>
					<uni-td>
						
						{{item.type_name}}
					</uni-td>
					<uni-td>
					<u-tag
						v-if="item.states == 0 ? true : false"
						style="margin-left: 10rpx; display: inline-block; width: 120rpx;text-align: center;"
						type="warning"
						text="待服务"
					></u-tag>
					
					
					<u-tag
						v-if="item.states == 1 ? true : false"
						style="margin-left: 10rpx; display: inline-block; width:150rpx;text-align: center;"
						type="success"
						
						text="完成服务"
					></u-tag>
					
					<u-tag
						v-if="item.states == 2 ? true : false"
						style="margin-left: 10rpx; display: inline-block; width: 140rpx;text-align: center;"
						type="error"
						text="拒绝服务"
					></u-tag>
					</uni-td>
					
					<uni-td>
						<u-button @click="wancheng(item)" v-if="item.states==0?true:false" 
						style="width: 120rpx;margin: 10rpx 0;" size="mini" type="primary" text="完成服务"></u-button>
						
						<u-button v-if="item.states==0?true:false"  @click="open(item)" style="width: 120rpx; margin: 10rpx 0;"  size="mini" type="error" text="拒绝服务"></u-button>
					</uni-td>
				</uni-tr>
			</uni-table>
		
		
		</view>
		
		<u-popup round="10" closeable mode="center" :show="poup_show" @close="close">
			<view class="popup_box">
				<view class="tit">拒绝理由</view>
				<view class="contnet_box">
					<u-form>
						<view class="item_input">
							<u-form-item labelWidth="80" label="拒绝理由"  ref="item1">
								<u--input style="width: 350rpx;" v-model="jujue_liyou"  disabledColor="#ffffff" 
								placeholder="请输入拒绝理由" ></u--input>
								
							</u-form-item>
						</view>
		
						<view class="add_btn" style="margin:40upx"><u-button type="success" 
						style="width: 320upx;height: 70upx;" text="确定" @click="jujue()"></u-button></view>
					</u-form>
				</view>
			</view>
		</u-popup>
		
		
	</view>
</template>

<script>
import { Request2 } from '@/until/api.js';
export default {
	data() {
		return {
			jujue_item:{},
			jujue_liyou:"",
			list: [],
			addForm: {
				roomnum: '',
				room_price: ''
			},
			poup_show: false,
			showsbuject:false,
			actions: [
						],
						addForm:{
							type_name:""
						}
			
		};
	
	
	},
	onShow() {
		this.getlist();
		this.getlist_fuwu()
	},
	methods: {
	async jujue(){
		console.log(this.jujue_item,"this.jujue_item.")
			var requsetdata={
				
				id:this.jujue_item.id,
				states:2,
				jujue_liyou:this.jujue_liyou,
				fuwu_user_name:uni.getStorageSync('supername')
				
			}
			var res = await Request2('/kefangfuwu/edit', 'post', requsetdata);
			if(res.data.code=="200"){
				
			
				this.$u.toast("拒绝服务成功!");
				this.poup_show=false;
				this.getlist()
			}else{
				this.$u.toast(res.data.msg);
			}
		},
		async wancheng(item){
			var requsetdata={
				id:item.id,
				states:1,
				fuwu_user_name:uni.getStorageSync('supername')
			}
			var res = await Request2('/kefangfuwu/edit', 'post', requsetdata);
			if(res.data.code=="200"){
				
			
				this.$u.toast("完成服务成功!");
				this.getlist()
			}else{
				this.$u.toast(res.data.msg);
			}
		},
	async add(){
			if(this.addForm.type_name==""){
				this.$u.toast('请选择服务类目!');
				return false
			}
			
			var user_accout = uni.getStorageSync('account');
			var user_name = uni.getStorageSync('supername');
			var requsetdata = {
				...this.addForm,
				user_accout: user_accout,
				user_name: user_name
			};
			var res = await Request2('/kefangfuwu/add', 'post', requsetdata);
			if (res.data.code == '200') {
				this.$u.toast('申请客房服务成功!');
				this.poup_show=false;
				this.showsbuject=false;
				this.addForm={
					type_name:""
				}
				this.getlist();
			} else {
				this.$u.toast(res.data.msg);
			}
			
			
		},
		Select(e) {
							this.addForm.type_name = e.name
							
						},
		open(item){
			console.log(item)
			 this.jujue_item=item;
			 this.poup_show = true;
		},
		close(){
			 this.jujue_item={}
			 this.poup_show = false
		},
		
		
		//获取服务类目列表
		async getlist_fuwu() {
			var requsetdata = {
				
			};
			var res = await Request2('/kefangfuwu/kefangfuwutoos', 'post', requsetdata);
			this.actions = res.data.data;
			console.log(this.list, 'this.list');
		},
		//获取列表
		async getlist() {
			var requsetdata = {
				user_type:2,
				user_accout: uni.getStorageSync('account')
			};
			var res = await Request2('/kefangfuwu/kefangfuwu', 'post', requsetdata);
			this.list = res.data.data;
			console.log(this.list, 'this.list');
		}
	}
};
</script>

<style lang="scss" scoped>
.my_kefang {
	background: #f1f1f1;
	min-height: 100vh;
	overflow: hidden;
	.myRoom_card {
		padding: 20rpx;
		.item {
			padding: 20rpx;
			margin: 20rpx 0;
			background: #fff;
			border-radius: 20rpx;
			view {
				margin: 10rpx 0;
			}
		}
	}
}

.top_box {
	margin: 20rpx;
	.addbtn {
		width: 150rpx;
		height: 80rpx;
	}
}
.popup_box {
	// background-color: #fff;
	width: 600upx;
	height: 400upx;

	overflow: hidden;

	box-sizing: border-box;
	// padding: 0 0upx;
	.contnet_box {
		padding: 20upx 20upx;
		.item_input {
			display: flex;
			width: 100%;
			// text-align: center;

			margin: 15upx 0;
			.label {
				line-height: 60upx;
			}
		}
	}

	.tit {
		text-align: center;
		margin-top: 40upx;
		font-size: 38upx;
		font-weight: 500;
	}
	.tips {
		margin: 60upx 0;
		color: #c2c2c2;
		font-size: 34upx;
		letter-spacing: 2upx;
	}
	.code {
		padding: 0;
		padding-left: 15upx;
	}
}
</style>
